import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _isEmpty from "lodash/isEmpty";

var _dec, _dec2, _dec3, _dec4, _class, _class2;

import React, { PureComponent } from 'react';
import { Bind } from 'lodash-decorators';
import { Form, Input, Button, Select, Row, Col } from 'antd';
import { SEARCH_COL_CLASSNAME, SEARCH_FORM_ROW_LAYOUT, FORM_COL_4_LAYOUT, SEARCH_FORM_ITEM_LAYOUT } from 'utils/constants';
import intl from 'utils/intl';
import { isTenantRoleLevel } from 'utils/utils';
var FormItem = Form.Item;
var modelPrompt = 'ciam.menuConfig.model.menuConfig';
var tenantRoleLevel = isTenantRoleLevel();
var QueryForm = (_dec = Form.create({
  fieldNameProp: null
}), _dec2 = Bind(), _dec3 = Bind(), _dec4 = Bind(), _dec(_class = (_class2 = /*#__PURE__*/function (_PureComponent) {
  _inherits(QueryForm, _PureComponent);

  var _super = _createSuper(QueryForm);

  function QueryForm(props) {
    var _this;

    _classCallCheck(this, QueryForm);

    _this = _super.call(this, props);
    _this.state = {
      expandForm: false
    };
    return _this;
  } // 查询条件展开/收起


  _createClass(QueryForm, [{
    key: "toggleForm",
    value: function toggleForm() {
      var expandForm = this.state.expandForm;
      this.setState({
        expandForm: !expandForm
      });
    }
  }, {
    key: "onClick",
    value: function onClick() {
      var _this$props = this.props,
          _this$props$handleQue = _this$props.handleQueryList,
          handleQueryList = _this$props$handleQue === void 0 ? function (e) {
        return e;
      } : _this$props$handleQue,
          _this$props$form$getF = _this$props.form.getFieldsValue,
          getFieldsValue = _this$props$form$getF === void 0 ? function (e) {
        return e;
      } : _this$props$form$getF;
      var data = getFieldsValue() || {};
      var _data$labels = data.labels,
          labels = _data$labels === void 0 ? [] : _data$labels;
      var param = _isEmpty(labels) ? '' : labels.join(',');
      handleQueryList(_objectSpread(_objectSpread({}, data), {}, {
        labels: param
      }), true);
    }
  }, {
    key: "handleLevelSelect",
    value: function handleLevelSelect(value) {
      var _this$props2 = this.props,
          _this$props2$handleQu = _this$props2.handleQueryList,
          handleQueryList = _this$props2$handleQu === void 0 ? function (e) {
        return e;
      } : _this$props2$handleQu,
          _this$props2$form$get = _this$props2.form.getFieldsValue,
          getFieldsValue = _this$props2$form$get === void 0 ? function (e) {
        return e;
      } : _this$props2$form$get;
      var data = getFieldsValue() || {};
      handleQueryList(_objectSpread(_objectSpread({}, data), {}, {
        level: value
      }));
    }
  }, {
    key: "onReset",
    value: function onReset() {
      var _this$props$form$rese = this.props.form.resetFields,
          resetFields = _this$props$form$rese === void 0 ? function (e) {
        return e;
      } : _this$props$form$rese;
      resetFields();
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props3 = this.props,
          _this$props3$form$get = _this$props3.form.getFieldDecorator,
          getFieldDecorator = _this$props3$form$get === void 0 ? function (e) {
        return e;
      } : _this$props3$form$get,
          _this$props3$searchLa = _this$props3.searchLabels,
          searchLabels = _this$props3$searchLa === void 0 ? [] : _this$props3$searchLa,
          levelCode = _this$props3.levelCode;
      var expandForm = this.state.expandForm;
      var levelCodeList = levelCode && levelCode.filter(function (o) {
        return o.value !== 'org';
      }) || [];

      var _levelCodeList = _slicedToArray(levelCodeList, 1),
          _levelCodeList$ = _levelCodeList[0],
          levelObj = _levelCodeList$ === void 0 ? {} : _levelCodeList$;

      var _levelObj$value = levelObj.value,
          levelValue = _levelObj$value === void 0 ? '' : _levelObj$value;
      return /*#__PURE__*/React.createElement(Form, {
        className: "more-fields-search-form"
      }, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Row, Object.assign({
        type: "flex",
        gutter: 24,
        align: "bottom"
      }, SEARCH_FORM_ROW_LAYOUT), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get("".concat(modelPrompt, ".name")).d('目录/菜单')
      }), getFieldDecorator('name')( /*#__PURE__*/React.createElement(Input, null)))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get("".concat(modelPrompt, ".parentName")).d('上级目录')
      }), getFieldDecorator('parentName')( /*#__PURE__*/React.createElement(Input, null)))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, !tenantRoleLevel ? /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get("".concat(modelPrompt, ".level")).d('层级')
      }), getFieldDecorator('level', {
        initialValue: levelValue
      })( /*#__PURE__*/React.createElement(Select, {
        allowClear: true,
        onSelect: this.handleLevelSelect
      }, levelCodeList.map(function (n) {
        return /*#__PURE__*/React.createElement(Select.Option, {
          key: n.value,
          value: n.value
        }, n.meaning);
      })))) : /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get("".concat(modelPrompt, ".quickIndex")).d('快速索引')
      }), getFieldDecorator('quickIndex')( /*#__PURE__*/React.createElement(Input, {
        inputChinese: false
      })))), /*#__PURE__*/React.createElement(Col, Object.assign({}, FORM_COL_4_LAYOUT, {
        className: SEARCH_COL_CLASSNAME
      }), /*#__PURE__*/React.createElement(Form.Item, null, /*#__PURE__*/React.createElement(Button, {
        style: {
          display: expandForm ? 'none' : 'inline-block'
        },
        onClick: this.toggleForm
      }, intl.get("cpaas.common.button.viewMore").d('更多查询')), /*#__PURE__*/React.createElement(Button, {
        style: {
          display: expandForm ? 'inline-block' : 'none'
        },
        onClick: this.toggleForm
      }, intl.get('cpaas.common.button.collected').d('收起查询')), /*#__PURE__*/React.createElement(Button, {
        "data-code": "reset",
        onClick: this.onReset.bind(this)
      }, intl.get('cpaas.common.button.reset').d('重置')), /*#__PURE__*/React.createElement(Button, {
        type: "primary",
        htmlType: "submit",
        onClick: this.onClick
      }, intl.get('cpaas.common.button.search').d('查询'))))), /*#__PURE__*/React.createElement(Row, Object.assign({
        style: {
          display: expandForm ? '' : 'none'
        }
      }, SEARCH_FORM_ROW_LAYOUT), !tenantRoleLevel && /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get("".concat(modelPrompt, ".quickIndex")).d('快速索引')
      }), getFieldDecorator('quickIndex')( /*#__PURE__*/React.createElement(Input, {
        inputChinese: false
      })))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: intl.get("ciam.roleManagement.model.roleManagement.labels").d('标签')
      }), getFieldDecorator('labels')( /*#__PURE__*/React.createElement(Select, {
        allowClear: true,
        mode: "multiple"
      }, searchLabels.map(function (n) {
        return /*#__PURE__*/React.createElement(Select.Option, {
          key: n.id,
          value: n.name
        }, n.name);
      }))))))));
    }
  }]);

  return QueryForm;
}(PureComponent), (_applyDecoratedDescriptor(_class2.prototype, "toggleForm", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "toggleForm"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "onClick", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "onClick"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleLevelSelect", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "handleLevelSelect"), _class2.prototype)), _class2)) || _class);
export { QueryForm as default };